package com.rt.cms.controller.openAPI;

import com.rt.cms.data.entity.TbCompanyInfo;
import com.rt.cms.data.requestParam.ArchivesParams;
import com.rt.cms.service.CompanyInfoService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Create with IDEA
 *
 * @author Wangzs
 * @Description
 * @Date 2018/6/19
 * @Time 10:19
 */
@Controller
@RequestMapping("/openapi")
public class PhpAPI {
    @Autowired
    private CompanyInfoService companyInfoService;

    @ResponseBody
    @RequestMapping(value = "/firstBidNotice")
    public Map<String, Object> FirstBidNotice(HttpServletRequest request) {
        Map map = new HashMap();
        String comId = request.getParameter("comId");
        String proId = request.getParameter("proId");
        String idNo = request.getParameter("idNo");

        ArchivesParams archivesParams = new ArchivesParams();
        archivesParams.setBusinessCode(idNo);
        archivesParams.setComId(Integer.parseInt(comId));
        archivesParams.setProId(Integer.parseInt(proId));
        try {
            if (companyInfoService.updateByPhpParam(archivesParams) > 0) {
                map.put("status", "0");
                map.put("msg", "ok");
            } else {
                map.put("status", "0");
                map.put("msg", "更新失败");
            }

        } catch (Exception e) {
            map.put("status", "1");
            map.put("msg", "操作失败");
            e.printStackTrace();
        } finally {
            return map;
        }
    }

    @ResponseBody
    @RequestMapping(value = "/findByIdNo")
    public Map<String, Object> findByIdNo(HttpServletRequest request) {
        Map map = new HashMap();
        String idNo = request.getParameter("idNo");
        ArchivesParams archivesParams = new ArchivesParams();
        archivesParams.setBusinessCode(idNo);

        try {
            List<TbCompanyInfo>   tbCompanyInfoList = companyInfoService.selectByPhpParam(archivesParams);
            JSONArray.fromObject(tbCompanyInfoList);
            map.put("status","0");
            map.put("result","ok");
        } catch (Exception e) {
            map.put("status", "1");
            map.put("msg", "操作失败");
        }
        return map;
    }
}
